package com.wuyou.simple;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 1608. 特殊数组的特征值
 * @Author 无忧
 * @Date 2022/9/14 21:53
 */
public class SpecialArray {

    public static void main(String[] args) {
        SpecialArray specialArray = new SpecialArray();
        int[] nums = {0, 0};
        System.out.println(specialArray.solution_1(nums));
    }

    public int solution_1(int[] nums) {

        Map<Integer, Integer> map = new HashMap<>();
        int num = nums.length;
        while (num > 0) {
            for (int i = 0; i < nums.length; i++) {
                map.put(num, map.getOrDefault(num, 0));
                if (nums[i] >= num) {
                    map.put(num, map.getOrDefault(num, 0) + 1);
                }
            }
            if (map.get(num) == num) {
                return num;
            }
            num--;
        }
        return -1;
    }
}
